package model.auxillary;

/**
 * A {@code Tool} is a specific {@code ParameterCollection} that handles
 * parameter identification in a different way than a
 * {@code ParameterCollection}.
 * @author Oliver Eckstein
 *
 */
public class Tool extends ParameterCollection {
	
	/**
	 * The rank of this tool inside it's {@code ParameterList}.
	 */
	private int rank;
	
	/**
	 * To create a new {@code Tool}.
	 * @param desc the description of this collection.
	 * @param idString an identifying ID.
	 * @param partProcessID the part process' ID.
	 * @param rank the rank of this tool inside it's {@code ParameterList}.
	 */
	public Tool(String name, String idString, String partProcessID, int rank) {
		super(name, idString, partProcessID);
		this.rank = rank;
	}
	
	@Override
	public Parameter getParameterByAbbrev(String abbreviation) {
		for (Parameter param : parameters) {
			// Example: when the parameter 'd_0' is searched it can by found by
			// looking for 'd' inside this tool.
			String a = abbreviation + "_" + rank;
			String b = abbreviation + "," + rank;
			if (param.getAbbreviation().equals(a) ||
					param.getAbbreviation().equals(b)) {
				return param;
			}
		}		
		return null;
	}
	
	@Override
	public String getName() {
		return desc;
	}
	
	@Override
	public String toString() {
		return desc;
	}
	
	@Override
	public void setName(String desc) {
		this.desc = desc;
	}

}
